<?php
	class FacebookModel
	{
		private $m_facebookObj = null;
		private $m_user_profile = null;
		
		public function __construct($config)
		{
			$this->m_facebookObj = new Facebook($config);
			$user = $this->m_facebookObj->getUser();
			
			if($user)
			{
				try 
				{
					$this->m_user_profile = $this->m_facebookObj->api('/me');
				}
				catch(FacebookApiException $e)
				{
					// Uncomment will print error msg, but might break the site at current state
					//echo $e->getMessage();
				}
			}	
		}
		
		public function isLoggedIn()
		{
			if($this->m_user_profile != null)
			{
				return true;
			}
			return false;
		}
		
		public function getLoginUrl()
		{			
			if($this->m_user_profile)
			{
				$loggUrl = array("type" => "Logout" , "url" => $this->m_facebookObj->getLogoutUrl());
			}
			else 
			{
				$loggUrl = array("type" => "Login" , "url" => $this->m_facebookObj->getLoginUrl());
			}			
			return $loggUrl;
		}
		
		public function getFacebookObject()
		{
			return $this->m_facebookObj;
		}
	}